package com.newegg.app.qec.util;

import android.app.AlertDialog;
import android.content.Context;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.newegg.app.qec.R;

/**
 * Created by Allen on 2017/12/11.
 */
public class MyDialog {
    private static AlertDialog ad;
    private static AlertDialog out;
    //个人信息性别选择弹窗
    private TextView title_tv, content_tv1, content_tv2, content_tv3,cancel_tv;

    /**
     * 性别选择弹窗
     *
     * @param context
     * @param layout
     * @return
     */
    public AlertDialog sex_Dialog(Context context, int layout) {
        ad = new AlertDialog.Builder(context, R.style.dialog).create();
        ad.setCancelable(true);
        ad.show();
        // 关键在下面的两行,使用window.setContentView,替换整个对话框窗口的布局
        Window window = ad.getWindow();
        assert window != null;
        window.setContentView(layout);
        //得到控件
        title_tv = (TextView) window.findViewById(R.id.title_tv);
        content_tv1 = (TextView) window.findViewById(R.id.content_tv1);
        content_tv2 = (TextView) window.findViewById(R.id.content_tv2);
        content_tv3 = (TextView) window.findViewById(R.id.content_tv3);
        return ad;
    }

    /**
     * 拍照选择弹窗
     *
     * @param context
     * @param layout
     * @return
     */
    public AlertDialog photo_Dialog(Context context, int layout) {
        ad = new AlertDialog.Builder(context, R.style.dialog).create();
        ad.setCancelable(true);
        ad.show();
        // 关键在下面的两行,使用window.setContentView,替换整个对话框窗口的布局
        Window window = ad.getWindow();
        assert window != null;
        window.setContentView(layout);
        window.setGravity(Gravity.BOTTOM);//窗口从底部弹出

        //弹窗宽度占满屏幕
        window.getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = WindowManager.LayoutParams.FILL_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(lp);
        //得到控件
        title_tv = (TextView) window.findViewById(R.id.title_tv);
        content_tv1 = (TextView) window.findViewById(R.id.take_photo_tv);
        content_tv2 = (TextView) window.findViewById(R.id.album_tv);
        cancel_tv = (TextView) window.findViewById(R.id.cancel_tv);
        return ad;
    }
    //提供内容选择控件

    public TextView getContent_tv1() {
        return content_tv1;
    }

    //提供内容选择控件
    public TextView getContent_tv2() {
        return content_tv2;
    }

    //提供内容选择控件
    public TextView getContent_tv3() {
        return content_tv3;
    }

    //提供取消控件
    public TextView getCancel_tv() {
        return cancel_tv;
    }

    //关闭
    public void dismiss() {
        ad.dismiss();
        ad = null;
    }
}
